package net.tuandn.training.lesson.gson;

import java.lang.reflect.Type;

import net.tuandn.training.model.City;
import net.tuandn.training.model.GenericResult;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class GenericDeserializer {

    public static void main(String[] args) {
        String cityPageLoadJson = "{\"count\":2,\"pageLoad\":[{\"id\":4,\"name\":\"HAN\"},{\"id\":8,\"name\":\"SGN\"}]}";
        Type type = new TypeToken<GenericResult<City>>() {
            // an anonymous inner class
        }.getType();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        GenericResult<City> cityPageLoad = gson.fromJson(cityPageLoadJson, type);
        for (City city : cityPageLoad.getPageLoad()) {
            System.out.println(gson.toJson(city));
        }
    }

    class DeleteMe {
        public void warm(){
            System.out.println("An inner class has name ContainingClass$myName.class on compiling!");
        }
    }
}
